package com.xj.zhihudemo.utils;

import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Xujing on 16/9/7.
 */
public class DateUtils {
    public static int daysOfTwo(String originalDate, String compareDateDate) {
        int nowDay = Integer.parseInt(originalDate);
        int originalDay = Integer.parseInt(compareDateDate);

        Log.e("nowDay", "" + nowDay);
        Log.e("compareDay", "" + originalDate);
        return originalDay - nowDay;
    }

    public static String FriendlyDate(String compareDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        Date nowDate = new Date(System.currentTimeMillis());//获取当前时间
        String str = formatter.format(nowDate);
        int dayDiff = daysOfTwo(str, compareDate);

        if (dayDiff <= 0)
            return "今日热文";
        else if (dayDiff == 1)
            return "昨日";
        else if (dayDiff == 2)
            return "前日";
        else
            return new SimpleDateFormat("M月d日 E").format(compareDate);
    }
}

